package org.gp953.basic.util;

import org.gp953.user.domain.LoginInfo;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

public class LoginContext {



    public static LoginInfo getLoginInfo(HttpServletRequest request) {
        // 通过
        String token = request.getHeader("token");
        ServletContext servletContext = request.getSession().getServletContext();
        ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        RedisTemplate redisTemplate = (RedisTemplate)applicationContext.getBean("redisTemplate");
        LoginInfo loginInfo = (LoginInfo) redisTemplate.opsForValue().get(token);
        return loginInfo;
    }
}
